package com.tourlaid.mamagerment.ao.wx.impl

import com.github.pagehelper.Page
import com.github.pagehelper.PageHelper
import com.tourlaid.mamagerment.ao.wx.MyCommentAo
import com.tourlaid.mamagerment.dto.MyCommentDto
import com.tourlaid.mamagerment.entity.ResponseData
import com.tourlaid.mamagerment.service.CommentService
import com.tourlaid.mamagerment.util.DateUtil
import com.tourlaid.mamagerment.util.LoginUtil
import org.springframework.stereotype.Service
import org.springframework.util.CollectionUtils
import javax.annotation.Resource

/**
 * Created by xiaoyongge on 2017/9/7.
 */
@Service("myCommentAo")
class MyCommentAoImpl : MyCommentAo {


    @Resource
    val commentService: CommentService? = null

    override fun queryIToOther(pageNo: Int): ResponseData<MutableList<MutableMap<String, Any?>>> {
        var mutableList: MutableList<MutableMap<String, Any?>> = mutableListOf()
        var responseData = ResponseData(mutableList)
        PageHelper.startPage<MyCommentDto>(pageNo, 10, true)
        val page = commentService!!.queryByFromUserId(LoginUtil.userId!!) as Page<MyCommentDto>
        responseData.totalCount = page.getTotal()
        var resultList = page.getResult()
        if (CollectionUtils.isEmpty(resultList)) {
            return responseData
        }
        for (myCommentDto in resultList) {
            val createTime = DateUtil.getFormantDate(myCommentDto.createTime, DateUtil.DATA_FORMANT21)
            var mutableMap = mutableMapOf(
                    "nickName" to myCommentDto.nickName,
                    "comment" to myCommentDto.comment,
                    "thoughtId" to myCommentDto.thoughtId,
                    "thoughtContent" to myCommentDto.thoughtContent,
                    "createTime" to createTime,
                    "ownId" to myCommentDto.ownId)
            mutableList.add(mutableMap)
        }
        return responseData
    }

    override fun queryOtherToI(pageNo: Int): ResponseData<MutableList<MutableMap<String, Any?>>> {
        var mutableList: MutableList<MutableMap<String, Any?>> = mutableListOf()
        var responseData = ResponseData(mutableList)
        PageHelper.startPage<MyCommentDto>(pageNo, 10, true)
        val page = commentService!!.queryByToUserId(LoginUtil.userId!!) as Page<MyCommentDto>
        responseData.totalCount = page.getTotal()
        var resultList = page.getResult()
        if (CollectionUtils.isEmpty(resultList)) {
            return responseData
        }
        for (myCommentDto in resultList) {
            val createTime = DateUtil.getFormantDate(myCommentDto.createTime, DateUtil.DATA_FORMANT21)
            var mutableMap = mutableMapOf(
                    "nickName" to myCommentDto.nickName,
                    "comment" to myCommentDto.comment,
                    "thoughtId" to myCommentDto.thoughtId,
                    "thoughtContent" to myCommentDto.thoughtContent,
                    "createTime" to createTime,
                    "ownId" to myCommentDto.ownId)
            mutableList.add(mutableMap)
        }
        return responseData
    }

}